package com.medusa.aps.business.modules.modeling.model.input;

import com.medusa.aps.business.model.constant.RegexPool;
import com.medusa.aps.business.modules.modeling.mp.entity.ProcessRoute;
import com.medusa.aps.business.common.web.valid.group.Update;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 工艺路线接收实体
 *
 * @author miskw
 * @date 2023/9/2
 */
@Data
@Accessors(chain = true)
@Schema(description = "工艺路线接收实体")
public class ProcessRouteDTO {
    /**
     * 工艺路线id
     */
    @Schema(description = "工艺路线id")
    @NotNull(message = "工艺路线id不能为空", groups = Update.class)
    private Integer processRouteId;
    /**
     * 工艺路线编码
     */
    @Schema(description = "工艺路线编码")
    @NotNull(message = "工艺路线编码不能为空")
    @Size(max = 50, message = "工艺路线编码不能超过50个字")
    @Pattern(regexp = RegexPool.ORDER_NO, message = "工艺路线编码只能数字、字母、符号等符号组成")
    private String processRouteCode;
    /**
     * 工艺路线名称
     */
    @Schema(description = "工艺路线名称")
    @NotNull(message = "工艺路线名称不能为空")
    @Size(max = 50, message = "工艺路线名称不能超过50个字")
    private String processRouteName;
    /**
     * 工艺路线描述
     */
    @Schema(description = "工艺路线描述")
    @Size(max = 50, message = "工艺路线描述最大支持50个字")
    private String processRouteDesc;
    /**
     * 备注
     */
    @Schema(description = "备注")
    @Size(max = 50, message = "备注最多只能填写50个字")
    private String remarks;
    /**
     * 物料id
     */
    @Schema(description = "物料id")
    @NotNull(message = "物料id不能为空")
    private Long materialId;
    /**
     * 物料编码
     */
    @Schema(description = "物料编码")
    @NotNull(message = "物料编码不能为空")
    private String materialCode;
    /**
     * 工艺工序
     */
    @Valid
    @Schema(description = "工艺工序")
    @Size(min = 1, message = "工艺工序至少一条")
    private List<TechnologicalProcessDTO> technologicalProcess;

    public ProcessRoute toProcessRoute() {
        return new ProcessRoute()
                .setId(processRouteId)
                .setProcessRouteCode(processRouteCode)
                .setProcessRouteName(processRouteName)
                .setProcessRouteDesc(processRouteDesc)
                .setRemarks(remarks)
                .setMaterialId(materialId)
                .setMaterialCode(materialCode);
    }
}
